#ifndef _CONFIG_H_
#define _CONFIG_H_
#include <Arduino.h>
#include "WiFi.h"
#include "PubSubClient.h"
#include "Preferences.h"
#include "HX711.h"
#include "Preferences.h"
#include "mqtt.h"
#include "ArduinoJson.h"
#include "HttpsOTAUpdate.h"

#define VERSION "240729"

extern  Preferences pref;
extern uint8_t pow_state;
extern uint8_t work_state;
extern uint8_t pub_state;
extern int mqtt_jzz;

extern uint natie_time;
extern uint kabuqinuo_time;
extern uint yishi_time;
extern uint clean_time;
extern uint yeru_pluse;
extern uint max_time;
extern uint channel1_pluse;
extern uint channel2_pluse;
extern uint channel3_pluse;
extern uint channel4_pluse;
extern bool bee_pluse;
extern uint work_times;
extern bool door_reset;

/**
 * @brief 蜂鸣器判断参数
 * 旧机器2451 （2000，2500）蜂鸣器长鸣，渣盒  新机器3566（3300，3700）
 */
extern uint bee_interve1;
extern uint bee_interve2;
/**
 * @brief 咖啡机类型
 *  1：得颐
 *  2：新咖啡机
 * 
 */
extern uint machine_type;


/**
 * @brief 按键 gpio
 * key1  23  卡布奇诺       
 * key2  22  热水/奶沫      
 * key3  21  意式咖啡       
 * key4  19  菜单/退出
 * key5  18  拿铁咖啡/确认
 * key6  17  电源
 * 
 */
// #define KEY1 23
// #define KEY2 22
// #define KEY3 21
// #define KEY4 19
// #define KEY5 18
// #define KEY6 17
// #define VALVE2 16
// #define VALVE1 4
// #define FLOW_HALL 15
// #define PUMP 27
#define AD1OUT 32
#define AD1SCK 33
#define AD2OUT 25
#define AD2SCK 26
// #define DOOR_SWICH 14
// #define BEE_INPUT 13
// #define SCREEN_POWKEY 13
// #define SCREEN1 36
// #define SCREEN2 39
// #define SCREEN3 34
// #define SCREEN4 35
// #define SCREEN5 32
// #define SCREEN6 33
// #define SCREEN7 25
// #define SCREEN8 26

#define KEY1 23
#define KEY2 22
#define KEY3 21
#define KEY4 19
#define KEY5 18
#define KEY6 17
#define VALVE2 16
#define VALVE1 4
#define FLOW_HALL 36
#define DOOR_SWICH 14
#define BEE_INPUT 39
#define PUMP1 32
#define PUMP2 33
#define PUMP3 25
#define PUMP4 26
#define VALVEL 27

extern uint64_t chipid;
extern unsigned long control_time;

/**
 * @brief 
 * wifi config
 */
// 
extern String SSID;
extern String PASSWD;

// #define SSID "ZH Mate 50 Pro"
// #define PASSWD "tqh159www"

extern char host_name[30];
extern uint8_t mac_uint8[6];
extern char mac[17];
extern WiFiClient wifi_client;  


/**
 * @brief 
 * mqtt config
 */
extern PubSubClient mqtt_client;    
extern char mqtt_sub_topic[40];
extern char mqtt_pub_topic[40];
extern char account[40];
extern char passwd[40];

extern String mqtt_server;
extern uint8_t ip[4];
extern uint16_t mqtt_port;
// #define mqtt_server "42.192.123.47"
// #define mqtt_sub_topic "/c/0cdc7e5eaa10/get"
// #define mqtt_pub_topic "/c/0cdc7e5eaa10/send"
// #define account "0cdc7e5eaa10"
// #define passwd "coffee"
// #define mqtt_port  1883
// #define LEDC_sub_topic "esp32/ledc/ledc_control"
// #define LEDC_state_topic "esp32/ledc/ledc_state"


/**
 * @brief 二值信号量
 * 
 */
extern volatile SemaphoreHandle_t bleconfigSemaphore;




/**
 * @brief 
 * HX711
 */

extern HX711 scale1;
extern HX711 scale2;
#define  scale1_threshold 500
#define  scale2_threshold 200

/**
 * @brief 
 * pump
 */

#define PWM_CHANNEL     0
#define PWM_CHANNEL1     1
#define PWM_CHANNEL2     2
#define PWM_CHANNEL3     3
#define PWM_CHANNEL4     4

/**
 * @brief 
 * hall
 */

extern uint64_t hall_count;


#endif 